package com.leps.nq.sys.controller;

import com.leps.nq.common.aspect.Log;
import com.leps.nq.common.enums.BusinessType;
import com.leps.nq.common.vo.PageVo;
import com.leps.nq.common.vo.R;
import com.leps.nq.common.vo.RBuilder;
import com.leps.nq.sys.entity.SysLogininfor;
import com.leps.nq.sys.service.ISysLogininforService;
import com.leps.nq.sys.vo.LogininfoQueryModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统访问记录 前端控制器
 * </p>
 *
 * @author hex
 * @since 2022-05-20
 */
@RestController
@RequestMapping("/sys/sys-logininfor")
@Api(tags = "登录日志管理")
public class SysLogininforController {
    @Autowired
    ISysLogininforService logininforService;

    @ApiOperation("登录日志列表")
    @GetMapping
    public R<PageVo<SysLogininfor>> list(LogininfoQueryModel queryModel) {
        PageVo<SysLogininfor> vo = this.logininforService.pageByQueryModel(queryModel);
        return RBuilder.ok(vo);
    }

    @ApiOperation("删除登录日志")
    @DeleteMapping
    @Log(title = "系统登录日志", businessType = BusinessType.DELETE)
    public R remove(@RequestBody List<Long> id) {
        boolean deleted = this.logininforService.removeBatchByIds(id);
        return RBuilder.ofBoolean(deleted);
    }

    @ApiOperation("清空登录日志")
    @DeleteMapping("/clear")
    @Log(title = "系统登录日志", businessType = BusinessType.DELETE)
    public R clear() {
        this.logininforService.clear();
        return RBuilder.ok();
    }
}
